﻿//
// Copyright (c) 2011 Western Data Solutions (www.westerndatasolutions.com) (Armen Shimoon)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 
// the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections.Generic;

namespace WDS.Bencode.Torrents
{
    /// <summary>
    /// Strongly typed representation of a torrent info header
    /// </summary>
    public class TorrentInfoHeader : BencodeDictionary
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="values">Info header dictionary</param>
        public TorrentInfoHeader(IEnumerable<KeyValuePair<BencodeString,BencodeElement>> values)
        {
            foreach (var keyValuePair in values)
            {
                Add(keyValuePair);
            }
            // Use a stongly typed representation of the file list
            SetValue("files", new TorrentFiles(ValueOfType<BencodeList<TorrentFile>>("files")));
        }

        public TorrentInfoHeader()
        {
            
        }
        /// <summary>
        /// Name of the torrent
        /// </summary>
        public string Name
        {
            get { return ValueOfType<BencodeString>("name").Value; }
            set { SetValue("name", value); }
        }

        /// <summary>
        /// List of the files in the torrent
        /// </summary>
        public TorrentFiles Files
        {
            get { return ValueOfType<TorrentFiles>("files"); }
            set { SetValue("files", value);}
        }

        /// <summary>
        /// Length of the torrent data
        /// </summary>
        public int Length
        {
            get { return ValueOfType<BencodeInteger>("length").Value; }
            set { SetValue("length", value); }
        }

        /// <summary>
        /// Length of each piece of file data
        /// </summary>
        public int PieceLength
        {
            get { return ValueOfType<BencodeInteger>("piece length").Value; }
            set { SetValue("piece length", value); }
        }

        /// <summary>
        /// Number of file pieces
        /// </summary>
        public string Pieces
        {
            get { return ValueOfType<BencodeString>("pieces").Value; }
            set { SetValue("pieces", value); }
        }

        /// <summary>
        /// Name of the Torrent publisher
        /// </summary>
        public string Publisher
        {
            get { return ValueOfType<BencodeString>("publisher").Value; }
            set { SetValue("publisher", value); }
        }

        /// <summary>
        /// Url of the Torrent publisher
        /// </summary>
        public string PublisherUrl
        {
            get { return ValueOfType<BencodeString>("publisher-url").Value; }
            set { SetValue("publisher-url", value); }
        }
    }
}